package eSn.File;

import java.util.*;

import eSn.Core.Structure.KeyValue;

public class PropertiesFile extends TextFile {

	private List<KeyValue> all;
		
	public PropertiesFile(String FileName,CharSet cs) throws Exception {
		super(FileName,cs);
		//载入
		List<String> a = super.LoadtoList();
		all = new ArrayList<KeyValue>();
		for(String s : a){
			if (s.length()>3){
				if (!s.substring(0, 1).equals("#")){
					if (!s.substring(0, 2).equals("//")){
						if (s.indexOf("=")>0){
							all.add(new KeyValue(s.substring(0, s.indexOf("=")),s.substring(s.indexOf("=")+1)));
						}						
					}
				}
			}
		}
	}
	
	public List<KeyValue> getAllKeyValue(){
		return all;
	}
	
	public String get(String Key){
		for(KeyValue kv :all){
			if(kv.Key.equals(Key)) return kv.Value.toString();
		}
		return null;
	}
	
}
